Can be done using https://htaccess.mwl.be/
AuthName "Authenticate"
AuthUserFile /some/path/.htpasswd
AuthType basic
Require valid-user
Order deny,allow
Deny from all
# Exceptions:
#Allow from 1.2.3.4
#Allow from googlebot.com
Satisfy Any
Redirect 301 <old path> <new path>
With pattern
<FilesMatch "^image.*$">
</FilesMatch>
Explicit
<Files upload.php>
# Do auth
</Files>
ErrorDocument 403 http://domain.com/unauthorized
Order deny,allow
Deny from all
Allow from vpn.domain.com
For example Perl:
Options +ExecCGI
AddHandler cgi-script cgi pl
Options -ExecCGI
AddHandler cgi-script <script file extensions>
ForceType application/x-httpd-php
SetEnv SERVER_ADMIN webmaster@domain.com
AddDefaultCharset UTF-8
DefaultLanguage en-US